package com.gulimall.product.web;

import com.gulimall.product.entity.CategoryEntity;
import com.gulimall.product.service.CategoryService;
import com.gulimall.product.vo.CataAjaxVo2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index","index.html"})
    public String index(Model model){
        List<CategoryEntity> categoryEntityList=categoryService.getAllParentList();
        model.addAttribute("categoryList",categoryEntityList);
        return "index";
    }
    @ResponseBody
    @RequestMapping("/json/catalog.json")
    public Map<Long,List<CataAjaxVo2>> getAjaxCateTree(){
        Map<Long,List<CataAjaxVo2>> map=categoryService.getAjaxCateTree();
        return map;
    }
}
